var numList = [];
var bigList = [];
var smallList = [];
var speList = ["_"]; //允许使用的特殊字符

for (var i = 48; i <= 57; i++) {
    var char = String.fromCharCode(i);
    numList.push(char);
}
console.log(numList);

for (var i = 65; i <= 90; i++) {
    var char = String.fromCharCode(i);
    bigList.push(char);
}
console.log(bigList);

for (var i = 97; i <= 122; i++) {
    var char = String.fromCharCode(i);
    smallList.push(char);
}
console.log(smallList);
var normalList = numList.concat(bigList, smallList, speList);



function randCode() {
    var list = numList.concat(bigList, smallList);
    var codeList = [];
    for (var i = 0; i < 4; i++) { // i = 2 不重复 本次结束  i++ =>3
        var index = Math.round(Math.random() * (list.length - 1));
        var char = list[index];
        if (codeList.indexOf(char) == -1) {
            codeList.push(char);   // 每次放之前判断codeList中是否能存在  不存在:放  存在:不放
        } else {
            // console.log(char + "重复 再来一次");
            i--;  //重复   i-- => i = 1  循环结束  i++  => 2    反复横跳(返回上一个存档点 在进入下一个)
        }
    }
    return codeList.join("");
}


function dateFormat(pattern) {  // "YY-MM-DD hh:mm:ss" 
    var now = new Date();

    var year = now.getFullYear();

    var month = now.getMonth() + 1;

    var day = now.getDate();

    var week = now.getDay();  // (0-6)
    var weekList = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]

    var hour = now.getHours();

    var minute = now.getMinutes();

    var second = now.getSeconds();

    // beauty版
    return pattern.replace("YY", year).replace("MM", beauty(month)).replace("DD", beauty(day)).replace("hh", beauty(hour)).replace("mm", beauty(minute)).replace("ss", beauty(second));
}


function beauty(num) {
    return num < 10 ? "0" + num : num;
}